package cn.itcast.nems.studentrecord.service.settlement;

import cn.itcast.nems.studentrecord.constant.ReferenceTypeEnum;

/**
 * 退学结算
 *
 * @author liyong
 * create: 2023-11-17 11:30:21
 **/
public class SettlementCalculatorDropout extends DefaultSettlementCalculator {
    /**
     * 应收调整金额
     */
    private int receivableChangeAmount;

    public SettlementCalculatorDropout(SettlementResult originSettlementResult) {
        super(originSettlementResult, ReferenceTypeEnum.DROPOUT);
    }

    public SettlementCalculatorDropout() {
        super(null, ReferenceTypeEnum.DROPOUT);
    }

    @Override
    public SettlementResult calculate(SettlementData settlementData) {
        logger.info("退学结算: {} ", settlementData);
        
        SettlementResult result = new SettlementResult();
        result.setSettlementData(settlementData);
        result.setSettlementReason(this.referenceType.name());
        if (this.originSettlementResult == null) {
            super.doCalculate(result, settlementData);
        } else {
            result.setServiceDays(originSettlementResult.getServiceDays());
            result.setSettlementDays(originSettlementResult.getSettlementDays());
            result.setSettlementAmount(originSettlementResult.getSettlementAmount());
        }
        
        final int amount = 0;
        result.setTransferAmount(amount);
        
        this.receivableChangeAmount = result.getSettlementAmount() - settlementData.getActualAmountDue();
        logger.info("退学结算结果: {}, 结算后实际应付金额: {}", result, settlementData.getActualAmountDue());
        return result;
    }

    public int getReceivableChangeAmount() {
        return receivableChangeAmount;
    }
}
